package com.atguigu.gmall.realtime.bean;

import lombok.*;
import org.apache.commons.lang3.ObjectUtils;

import java.math.BigDecimal;

/**
 * 订单宽表实体类
 *
 * @author lvbingbing
 * @date 2022-03-27 20:06
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class OrderWide {

    /*-------------------- 1。订单详情表信息 --------------------*/

    /**
     * 订单详情表id
     */
    private Long detail_id;

    /**
     * 订单id
     */
    private Long order_id;

    /**
     * 商品id
     */
    private Long sku_id;

    /**
     * 购买价格(下单时sku价格）
     */
    private BigDecimal order_price;

    /**
     * 购买数量
     */
    private Long sku_num;

    /**
     * sku名称（冗余)
     */
    private String sku_name;

    /**
     * 地区
     */
    private Long province_id;

    /**
     * 订单状态
     */
    private String order_status;

    /**
     * 用户id
     */
    private Long user_id;

    /*-------------------- 2. 订单表信息 --------------------*/

    /**
     * 订单总金额
     */
    private BigDecimal total_amount;

    /**
     * 促销金额
     */
    private BigDecimal activity_reduce_amount;

    /**
     * 优惠券
     */
    private BigDecimal coupon_reduce_amount;

    /**
     * 原价金额
     */
    private BigDecimal original_total_amount;

    /**
     * 运费
     */
    private BigDecimal feight_fee;

    private BigDecimal split_feight_fee;

    private BigDecimal split_activity_amount;

    private BigDecimal split_coupon_amount;

    private BigDecimal split_total_amount;

    /**
     * 失效时间
     */
    private String expire_time;

    /**
     * 创建时间
     */
    private String create_time;

    /**
     * 操作时间
     */
    private String operate_time;

    /**
     * 将其他字段处理得到
     */
    private String create_date;

    /**
     * 将其他字段处理得到
     */
    private String create_hour;

    /*-------------------- 3. 查询维表得到 --------------------*/

    private String province_name;

    private String province_area_code;

    private String province_iso_code;

    private String province_3166_2_code;

    /*-------------------- 4. 查询维表得到 --------------------*/

    private Integer user_age;

    private String user_gender;

    /*----------------------------------------*/

    /**
     * 作为维度数据 要关联进来
     */
    private Long spu_id;

    private Long tm_id;

    private Long category3_id;

    private String spu_name;

    private String tm_name;

    private String category3_name;

    public OrderWide(OrderInfo orderInfo, OrderDetail orderDetail) {
        mergeOrderInfo(orderInfo);
        mergeOrderDetail(orderDetail);

    }

    public void mergeOrderInfo(OrderInfo orderInfo) {
        if (orderInfo != null) {
            this.order_id = orderInfo.getId();
            this.order_status = orderInfo.getOrder_status();
            this.create_time = orderInfo.getCreate_time();
            this.create_date = orderInfo.getCreate_date();
            this.activity_reduce_amount = orderInfo.getActivity_reduce_amount();
            this.coupon_reduce_amount = orderInfo.getCoupon_reduce_amount();
            this.original_total_amount = orderInfo.getOriginal_total_amount();
            this.feight_fee = orderInfo.getFeight_fee();
            this.total_amount = orderInfo.getTotal_amount();
            this.province_id = orderInfo.getProvince_id();
            this.user_id = orderInfo.getUser_id();
        }
    }

    public void mergeOrderDetail(OrderDetail orderDetail) {
        if (orderDetail != null) {
            this.detail_id = orderDetail.getId();
            this.sku_id = orderDetail.getSku_id();
            this.sku_name = orderDetail.getSku_name();
            this.order_price = orderDetail.getOrder_price();
            this.sku_num = orderDetail.getSku_num();
            this.split_activity_amount = orderDetail.getSplit_activity_amount();
            this.split_coupon_amount = orderDetail.getSplit_coupon_amount();
            this.split_total_amount = orderDetail.getSplit_total_amount();
        }
    }

    public void mergeOtherOrderWide(OrderWide otherOrderWide) {
        this.order_status = ObjectUtils.firstNonNull(this.order_status, otherOrderWide.order_status);
        this.create_time = ObjectUtils.firstNonNull(this.create_time, otherOrderWide.create_time);
        this.create_date = ObjectUtils.firstNonNull(this.create_date, otherOrderWide.create_date);
        this.coupon_reduce_amount = ObjectUtils.firstNonNull(this.coupon_reduce_amount, otherOrderWide.coupon_reduce_amount);
        this.activity_reduce_amount = ObjectUtils.firstNonNull(this.activity_reduce_amount, otherOrderWide.activity_reduce_amount);
        this.original_total_amount = ObjectUtils.firstNonNull(this.original_total_amount, otherOrderWide.original_total_amount);
        this.feight_fee = ObjectUtils.firstNonNull(this.feight_fee, otherOrderWide.feight_fee);
        this.total_amount = ObjectUtils.firstNonNull(this.total_amount, otherOrderWide.total_amount);
        this.user_id = ObjectUtils.<Long>firstNonNull(this.user_id, otherOrderWide.user_id);
        this.sku_id = ObjectUtils.firstNonNull(this.sku_id, otherOrderWide.sku_id);
        this.sku_name = ObjectUtils.firstNonNull(this.sku_name, otherOrderWide.sku_name);
        this.order_price = ObjectUtils.firstNonNull(this.order_price, otherOrderWide.order_price);
        this.sku_num = ObjectUtils.firstNonNull(this.sku_num, otherOrderWide.sku_num);
        this.split_activity_amount = ObjectUtils.firstNonNull(this.split_activity_amount);
        this.split_coupon_amount = ObjectUtils.firstNonNull(this.split_coupon_amount);
        this.split_total_amount = ObjectUtils.firstNonNull(this.split_total_amount);
    }
}

